package com.infoland.afanmall.base.util;

import android.content.Context;
import android.content.SharedPreferences;
import android.support.v7.app.AppCompatActivity;

import com.alibaba.fastjson.JSONObject;


/**
 * 全局临时缓存变量
 */
public class CacheKit {
    public static Context APP_CONTEXT;
    public static AppCompatActivity ACTIVITY;
    /***存储空间**/
    public static String SpaceName = "AfanAppCache";

    /***当前网络状态*/
    public static boolean INTERNET = true;


    public static boolean getBoolean(String key) {
        SharedPreferences sp = CacheKit.APP_CONTEXT.getSharedPreferences(SpaceName, Context.MODE_PRIVATE);
        return sp.getBoolean(key, false);
    }

    public static void putBoolean(String key, boolean b) {
        SharedPreferences sp = CacheKit.APP_CONTEXT.getSharedPreferences(SpaceName, Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = sp.edit().putBoolean(key, b);
        editor.apply();
    }

    public static String getString(String key) {
        SharedPreferences sp = CacheKit.APP_CONTEXT.getSharedPreferences(SpaceName, Context.MODE_PRIVATE);
        return sp.getString(key, "");
    }

    public static void putString(String key, String str) {
        SharedPreferences sp = CacheKit.APP_CONTEXT.getSharedPreferences(SpaceName, Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = sp.edit().putString(key, str);
        editor.apply();
    }

    public static int getInt(String key) {
        SharedPreferences sp = CacheKit.APP_CONTEXT.getSharedPreferences(SpaceName, Context.MODE_PRIVATE);
        return sp.getInt(key, 0);
    }

    public static void putInt(String key, int b) {
        SharedPreferences sp = CacheKit.APP_CONTEXT.getSharedPreferences(SpaceName, Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = sp.edit().putInt(key, b);
        editor.apply();
    }

    //优选，下方商品排序
    public static class YouXuan {
        /***当前Tab位置  0-综合, 1-销量, 2-价格, 3-最新*/
        public static int TAB_TYPE = 0;

        /*** true(升序)  false(降序)**/
        /***销量 排序状态  */
        public static boolean XIAO_LIANG = true;
        /***价格 排序状态  */
        public static boolean PRICE = true;
        /***最新 排序状态  */
        public static boolean TIME = false;
        /***综合 排序状态 */
        public static boolean ZONG_HE = false;

        // INIT_SIZE
        public static int XIAO_LIANG_PAGE_SIZE = 10;
        public static int PRICE_PAGE_SIZE = 10;
        public static int TIME_PAGE_SIZE = 10;
        public static int ZONG_HE_PAGE_SIZE = 10;

        //        NOW
        public static int NOW_PAGE_NUMBER = 1;
        public static int NOW_PAGE_SIZE = 10;
        public static boolean NOW_PAGE_LAST = false;
        public static JSONObject NOW_ORDER_BY = null;

    }

    //拼团 下方 TAB
    public static class PinTuan {
        /***当前Tab位置  0-最新, 1-成团数, 2-已拼数量*/
        public static int TAB_TYPE = 0;

        /*** true(升序)  false(降序)**/
        public static boolean ZUI_XIN = true;
        public static boolean C_TUAN_SHU = true;
        public static boolean YP_SHU_LIANG = true;
        /*** 当前页码**/
        public static int NOW_PAGE_NUMBER = 1;
        public static int NOW_PAGE_SIZE = 5;
        /*** 是否最后一页**/
        public static boolean NOW_PAGE_LAST = false;
        /*** 排序**/
        public static JSONObject NOW_ORDER_BY = null;

    }

}
